package com.marktotop.controller.system;


import com.marktotop.entity.system.LoginLog;
import com.marktotop.response.ResultBean;
import com.marktotop.service.ILoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Arrays;

/**
 * <p>
 * 登录日志表 前端控制器
 * </p>
 *
 * @author MarkToTop
 * @since 2021-07-12
 */
@Api(tags = "系统模块-登录日志接口")
@RestController
@RequestMapping("/system/loginLog")
public class LoginLogController {

    @Autowired
    private ILoginLogService loginLogService;


    /**
     * 日志列表
     *
     * @return
     */
    @ApiOperation(value = "日志列表", notes = "登入日志列表，模糊查询")
    @RequestMapping(value = "/findLoginLogList",method = RequestMethod.GET)
    public ResultBean findLoginLogList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize") Integer pageSize,
                                       LoginLog loginLog) {
        return loginLogService.findLoginLogList(pageNum, pageSize, loginLog);
    }


    /**
     * 删除日志
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除日志",notes = "删除单条登录日志")
    @RequiresPermissions({"loginLog:delete"})
    @DeleteMapping("/delete/{id}")
    public ResultBean delete(@PathVariable Long id) {
        if (!loginLogService.removeById(id)){
            return ResultBean.error().message("删除登录日志操作失败!");
        }
        return ResultBean.ok().message("删除登录日志操作成功!");
    }


    /**
     * 批量删除登录日志
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除",notes = "批量删除多条登录日志")
    @RequiresPermissions({"loginLog:batchDelete"})
    @DeleteMapping("/batchDelete/")
    public ResultBean batchDelete( Long[] ids) {
        if (!loginLogService.removeByIds(Arrays.asList(ids))){
            return ResultBean.error().message("批量删除登录日志操作失败!");
        }
        return ResultBean.ok().message("批量删除登录日志操作成功!");
    }

}
